<?php
/*
// +----------------------------------------------------------------------------------------
// | Icoterie Development Framework Intelligence Enterprise Management Priority Selective
// +----------------------------------------------------------------------------------------
// | Copyright (c) [2019] [Honor Full Epoch Educational Science Technology Hebei Co., Ltd.]
// | website  http://dev.icoterie.top http://www.ihfe.top
// +----------------------------------------------------------------------------------------
// | [Icoterie Development Framework] is licensed under the Mulan PSL v2.
// +----------------------------------------------------------------------------------------
// | You can use this software according to the terms and conditions of the Mulan PSL v2.
// +----------------------------------------------------------------------------------------
// | Licensed ( http://license.coscl.org.cn/MulanPSL2 )
// +----------------------------------------------------------------------------------------
// | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER
// | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR
// | FIT FOR A PARTICULAR PURPOSE.
// +----------------------------------------------------------------------------------------
// | See the Mulan PSL v2 for more details.
// +----------------------------------------------------------------------------------------
// | Author: Reflux Lewse,Red Shadow Sue
// +----------------------------------------------------------------------------------------
// | 控制调度类
// +----------------------------------------------------------------------------------------
*/
namespace core\basic;
use core\basic\Config;
use core\basic\Response;
use core\basic\View;
class Controller
{
	/**
     * 视图实例
     * @var	array
     */
	private static $view;
	public function __construct()
    {
		$this->view = new View;
		//echo 'before111 class'.PHP_EOL;
	}
	/**
     * 变量注入
     * @access	public
     * @param	string|array	$k	变量名
     * @param	mixed			$v	变量值
     * @return	$this
     */
    public function assign($k, $v = null)
    {
        $this->view->assign($k, $v);
    }
	/**
     * 变量赋值
     * @access	public
     * @param	string	$k	变量名
     * @param	mixed	$v	变量值
     */
    public function setVar(string $k, $v)
    {
        $this->view->assign[$k] = $v;
    }

    /**
     * 变量提取
     * @access	protected
     * @param	string	$k	变量名
     * @return	mixed
     */
    public function getVar(string $k)
    {
        return $this->view->assign[$k];
    }

	/** 
	* 模板解析
	* @param	string	$f	模板文件
	*/
    public function dispaly($f)  
    {
		Response::checkDir(APP_VIEW_PATH);
		Response::checkDir(TEMP_PATH,true);
		Response::checkDir(CACHE_PATH,true);
		$f = Response::checkFile(APP_VIEW_PATH . $f . '.html');
		$this->view->dispaly($f);
    }

	/** 
	* 静态缓存
	* @param	string	$f	模板文件
	*/
    public function show($f)  
    {
		$f = APP_VIEW_PATH . $f . '.html';
		$f = CACHE_PATH . md5($f) . '.php';
		if(file_exists($f)){ 
			include_once $f;
			exit;
		}
    }
	
	

	/** 
	* 动态实例
	* @param	string	$c	类库
	* @param	string	$a	方法
	*/ 
    public function make($c,$a){
        //$this->before();
        $c->$a();
        //$this->after();
    }
	public function before(){
        echo '<div>before1 in Action</div>';
    }
    public function after(){
        echo '<div>after1 in Action</div>';
    }
}
?>
